package com.example.app2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;

public class GuideActivity extends AppCompatActivity {
    ViewPager vp;
    LinearLayout layout;
    ArrayList<ImageView> list;
    int resId[] = {R.mipmap.a,R.mipmap.b,R.mipmap.c,R.mipmap.d};
    GuideAdapter adapter;
    ArrayList<ImageView> pointlist;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        vp = findViewById(R.id.guide_vp);
        layout = findViewById(R.id.guide_layout);
        list = new ArrayList<>();
        pointlist =new ArrayList<>();
        for (int i = 0; i < resId.length; i++) {
            ImageView imageView = new ImageView(this);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setImageResource(resId[i]);
            list.add(imageView);
            ImageView piv = new ImageView(this);
            piv.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.MATCH_PARENT));
                    piv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    piv.setImageResource(R.mipmap.p0);
                    pointlist.add(piv);
                    layout.addView(piv);
        }
        pointlist.get(0).setImageResource(R.mipmap.p1);
        adapter = new GuideAdapter(this,list);
        vp.setAdapter(adapter);
        vp.addOnAdapterChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position){
                for (int i = 0; i < pointlist.size(); i++) {
                    pointlist.get(i).setImageResource(R.mipmap.p0);
                }
                pointlist.get(position).setImageResource(R.mipmap.p1);
            }
        });
    }
}